package com.yycx.module.bus.provider.handler.supplierbond;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.constants.CommonConstants;
import com.yycx.common.mybatis.interceptor.DeleteInterceptor;
import com.yycx.common.mybatis.query.CriteriaDelete;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.provider.service.BusOrderDetailsService;
import com.yycx.module.bus.provider.service.BusPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * 垫付款删除
 *
 * @author zyf
 */
@Component("supplierBondPaymentDeleteHandler")
public class SupplierBondPaymentDeleteHandler implements DeleteInterceptor {

    @Autowired
    private BusOrderDetailsService detailsService;
    @Autowired
    private BusPaymentService paymentService;


    @Override
    public void prepare(CriteriaDelete cd, EntityMap entityMap) {
        Serializable paymentId = cd.getIdValue();
        BusPayment payment=paymentService.getById(paymentId);
        entityMap.put("orderId",payment.getOrderId());
    }

    @Override
    public void complete(CriteriaDelete cq, EntityMap params) {
        Long orderId = params.getLong("orderId");
        //重置垫付状态
        detailsService.clearSupplierBondState(orderId, CommonConstants.INT_0);
    }
}
